var mongoose = require('mongoose');
var util = require('util');

mongoose.connect('mongobd://127.0.0.1/test');

require('./Device2');
require('./Port');

var d1 = new DeviceModel();
d1.name = "test1";
d1.hwAddress = '1';
d1.inetAddress = '1';

d1.save(function(e) {
	util.puts("Saving D1");
	p1 = new PortModel();
	p1.device = d1._id;
	p1.name = 'a';
	p1.id = 'asdf';

	p1.add(function(e) {
		DeviceModel.find({}).run(function(e, devices) {
			util.puts("Found " + devices.length + " Entries:");
			devices.forEach(function(device) {
				util.puts(util.inspect(device));
			});
		});
		
		DeviceModel.find({}).populate('ports').run(function(e, devices) {
			util.puts("Found " + devices.length + " Entries. Populated:");
			devices.forEach(function(device) {
				util.puts(util.inspect(device));
			});
		});
	});
});
